<?php

include_once './database.php';

class MySQLDatabase{

	private $connection;
	
	public function __construct(){
	
		$this->connect_database();
	}
	
	public function connect_database(){
		
		$this->connection = mysql_connect('localhost', 'root', 'password');
		if (!$this->connection){
		
			die("Cannot connect to database " . mysql_error());
		
		} else {
		
			$select_db = mysql_select_db('portal');
			
			if(!$select_db){
			
				die("Error in selecting database " . mysql_error());
			}
		}
	}
	
	public function query($sql){
	
		return mysql_query($sql, $this->connection);
	
	}
	
	public function fetch_array($result_set){
	
		return mysql_fetch_array($result_set);
	
	}
	
	public function fetch_assoc($result_set){
		
		return mysql_fetch_assoc($result_set);
	
	}
	
	public function num_rows($result_set){
	
		return mysql_num_rows($result_set);
	
	}
	
	public function affected_rows() {
		return mysql_affected_rows($this->connection);
    }
	


	public function close_connection(){
	
		if(isset($this->connection)) {
			mysql_close($this->connection);
			unset($this->connection);
		}
	
	}

}

$database = new MySQLDatabase();

